<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<button id="btn">按钮</button>
</body>
<script>

    document.getElementById('btn').onclick = function () {

        var name = prompt("请输入姓名");
        console.log(name);
    }
</script>
</html>